Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/fs/glob.sh

glob

Since 0.3.0 · Source

import "{ glob }" from nice_things/fs/glob.sh

Synopsis
glob <pattern>…

Configuration

Description
Perform pathname expansion (AKA globbing) on arguments. Prints a List of matched files.

Compared to pathname expansion as performed by the shell, this function behaves differently in that it does not print out the input pattern if that pattern fails to match any files.

This function includes a pure sh implementation of globstar, similar to that feature in bash. It works on any shell. You can use the globstar operator ** (double-asterisks) in a path segment to expand any number of subdirectories recursively. Only a single globstar in <pattern> will be treated as such. In case <pattern> contains multiple globstar operators, the later ones will be treated as if they were the single asterisk operator.

Warning

This function prints a List and can only be safely used in strict_mode.

Options

Operands
<pattern>: A glob pattern.

Stdin

Stdout
A List of matched files. Each <pattern> can expand to zero or more filenames.

Stderr

Exit status
0: Successful completion.

Abort

Usage examples

#{{{ strict_mode }}}
# Get all sh files in current and child directories
shell_scripts=$(glob ./**/*.sh)